package scenetracer;

import scenetracer.core.Primitive;
import scenetracer.core.Ray;
import scenetracer.core.Scene;
import scenetracer.core.primitive.IntersectionState;
import scenetracer.image.Color;
import scenetracer.math.Vector3;

public class SceneState {
	private SceneTracer sceneTracer;
	private Scene scene;
	private Color color;
	private Color reflecColor = new Color(Color.BLACK);
	private Color refracColor = new Color(Color.BLACK);
	private Primitive primitive;
	private Vector3 normal;
	private Vector3 reflecRayDir;
	
	
	private IntersectionState intersec;
	private Ray ray;

	public SceneState(SceneTracer rayTracer, Scene scene, Ray ray,
			Color color, Primitive primitive, IntersectionState intersection) {
		this.sceneTracer = rayTracer;
		this.scene = scene;
		this.ray = ray;
		this.color = color;
		this.primitive = primitive;
		this.intersec = intersection;
	}
	
	public void setTracer(SceneTracer tracer) {
		this.sceneTracer = tracer;
	}
		
	
	public Primitive getPrimitive() {
		return primitive;
	}
	
	public void setPrimitive(Primitive primitive) {
		this.primitive = primitive;
	}
	
	public void setColor(Color color) {
		this.color = color;
	}
	
	public void setIntersection(IntersectionState intersection) {
		this.intersec = intersection;
	}
	public void setRay(Ray ray) {
		this.ray = ray;
	}

	public void setScene(Scene scene) {
		this.scene = scene;
	}

	public void setReflectionColor(Color reflectionColor) {
		this.reflecColor = reflectionColor;
	}
	public void setRefractionColor(Color refractionColor) {
		this.refracColor = refractionColor;
	}
	public IntersectionState getIntersection() {
		return intersec;
	}
	
	public Color getRefractionColor() {
		return refracColor;
	}
	
	public Color getReflectionColor() {
		return reflecColor;
	}
	
	public Scene getScene() {
		return scene;
	}
	
	public Ray getRay() {
		return ray;
	}
	
	public Color getColor() {
		return color;
	}
	
	public Vector3 getNormal() {		
		if(normal == null){
			normal =  intersec.getNormal();
			//normal=primitive.getNormal(intersec);
		}		
		return normal;
	}
	
	public Vector3 getReflectedDirection() {
		if(reflecRayDir == null){
			Vector3 normal = new Vector3(getNormal());
			Vector3 direction = getRay().getDirection();
			float dot = Vector3.dot(normal, direction);
			reflecRayDir = Vector3.sub(direction,
					normal.mul(2 * dot), new Vector3());
			reflecRayDir.normalize();
		}
		
		return reflecRayDir;
	}
	
	public SceneTracer getTracer() {
		return sceneTracer;
	}
	
	
}
